<?
function dircopy($srcdir, $dstdir, $verbose = false) {
  $num = 0;
  if(!is_dir($dstdir)) mkdir($dstdir);
  if($curdir = opendir($srcdir)) {
   while($file = readdir($curdir)) {
     if($file != '.' && $file != '..') {
       $srcfile = $srcdir . '\\' . $file;
       $dstfile = $dstdir . '\\' . $file;
       if(is_file($srcfile)) {
         if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1;
         if($ow > 0) {
           if($verbose) echo "Copying '$srcfile' to '$dstfile'...";
           if(copy($srcfile, $dstfile)) {
             touch($dstfile, filemtime($srcfile)); $num++;
             if($verbose) echo "OK\n";
           }
           else echo "Error: '$srcfile' could not be copied!\n";
         }                 
       }
       else if(is_dir($srcfile)) {
         $num += dircopy($srcfile, $dstfile, $verbose);
       }
     }
   }
   closedir($curdir);
  }
  return $num;
}

?>

<html>
<head>
<title>oPanel</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="stylesheet"href="style.css" />
</head>
<body>
<? include('functions.php');
if(!isset($_SESSION["pass"]) || !isset($_SESSION["user"])) {
$path = $_SERVER["HTTP_HOST"].dirname("$_SERVER[SCRIPT_NAME]");
$html = <<<EFO
<script>
parent.location="http://$path/";
</script>
EFO;
die($html);
}
if(isset($_SESSION["pass"])) {
if ($_SESSION["pass"] == check($_SESSION["user"])) {
echo '<center><img src="images/logo.png"></center>';
}
}

if(!isset($_GET['new']) || !isset($_GET['old'])) {
die("Variables not set!");
}
$new = $_GET['new'];
$old = $_GET['old'];
if(isset($_GET['file'])) {
$file = $_GET['file'];
copy("$old$file", "$new$file");
echo "
<table border=0 width=100% valign=middle align=center>
<tr>
<td>
<img src=\"images/i-regular.gif\" border=\"0\" />
</td>
<td>
<img src=\"images/forward.gif\">
</td>
<td><img src=\"images/i-directory.gif\" width=\"16\" height=\"16\"> </td>
</tr>
<tr>
<td>
".$file."
</td>
<td>copied</td>
<td>
".$new."
</td>

</tr>
</table>";
} else {
$newfolder = $new."".basename($old);
dircopy("$old", "$newfolder");
echo "
<table border=0 width=100% valign=middle align=center>
<tr>
<td>
<img src=\"images/i-regular.gif\" border=\"0\" />
</td>
<td>
<img src=\"images/forward.gif\">
</td>
<td><img src=\"images/i-directory.gif\" width=\"16\" height=\"16\"> </td>
</tr>
<tr>
<td>
".basename($old)."
</td>
<td>copied</td>
<td>
".$newfolder."
</td>

</tr>
</table>";
}
?>
<script type="text/javascript">
parent.filemain.location="http://<? echo $_SERVER["HTTP_HOST"]; echo dirname("$_SERVER[SCRIPT_NAME]"); ?>/list.php?dir=<? echo dirname($old); ?>/";
</script>
</body>
</html>